package com.resou.reader.mine.vipcenter.monthlybooks;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.TextView;

import com.resou.reader.R;
import com.resou.reader.api.entry.BookCategoryBean;
import com.resou.reader.api.entry.ChannelBean;
import com.resou.reader.api.entry.FilterBean;
import com.resou.reader.base.ResouBaseActivity;
import com.resou.reader.bookstore.rank.adapter.FragmentAdapter;
import com.resou.reader.data.bookstore.model.PlateNovels;
import com.resou.reader.mine.vipcenter.monthlybooks.fragment.Fragment_monthly_boy;
import com.resou.reader.mine.vipcenter.monthlybooks.fragment.Fragment_monthly_gril;
import com.resou.reader.view.MagincIndicatorAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 包月书库
 */
public class MonthlyBooksActivity extends ResouBaseActivity<MonthlyBooksPresenter> implements IMonthlyBooksContract.IMonthlyBooksView, ViewPager.OnPageChangeListener {

    public static void start(Context context) {
        Intent starter = new Intent(context, MonthlyBooksActivity.class);
        context.startActivity(starter);
    }

    @BindView(R.id.mMagicIndicator)
    MagicIndicator mMagicIndicator;
    @BindView(R.id.rank_pager)
    ViewPager mViewPager;
    List<Fragment> mList = new ArrayList<>();
    List<ChannelBean> list = null;
    @BindView(R.id.ivBack)
    ImageView ivBack;
    @BindView(R.id.tvTitle)
    TextView tvTitle;

    @Override
    protected void initStatusBar() {

    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void initView() {
        tvTitle.setText("包月书库");
        list = new ArrayList<>();
        list.add(new ChannelBean(1, "男生小说"));
        list.add(new ChannelBean(2, "女生小说"));
        mList.add(new Fragment_monthly_boy());
        mList.add(new Fragment_monthly_gril());
        ClassicsFooter.REFRESH_FOOTER_NOTHING = "已经显示全部，到其他分类看看吧";
        bindViewPager();

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_monthly_books;
    }

    @Override
    public void retryRefreshData() {

    }

    @Override
    public void initData() {
    }

    @Override
    public void showContent() {
        dissLoading();
    }

    @Override
    public void showProgress() {
        showLoading();
    }

    @Override
    public void showError(Throwable throwable) {
    }

    @Override
    public void showEmpty() {
    }

    @Override
    public void showBookList(List<PlateNovels> list) {
    }

    @Override
    public void showFilter(List<FilterBean> bean) {

    }

    @Override
    public SmartRefreshLayout getSmartRefreshLayout() {
        return null;
    }

    /**
     * 绑定Viewpager与mMagicIndicator
     */
    private synchronized void bindViewPager() {
        FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), mList, this.list);
        fragmentAdapter.getPageTitle(0);
        mViewPager.setAdapter(fragmentAdapter);
        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdjustMode(true);
        mViewPager.addOnPageChangeListener(this);
        mViewPager.setCurrentItem(0);
        commonNavigator.setAdapter(new MagincIndicatorAdapter(this.list, mViewPager, true));
        mMagicIndicator.setNavigator(commonNavigator);
        ViewPagerHelper.bind(mMagicIndicator, mViewPager);
    }

    @Override
    public void onPageScrolled(int i, float v, int i1) {
    }

    @Override
    public void onPageSelected(int i) {
    }

    @Override
    public void onPageScrollStateChanged(int i) {
    }


    @OnClick(R.id.ivBack)
    public void onClick() {
        finish();
    }
}
